﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td width="1%">
            <%=Html.DropDownList("MasterProvinceList", null, Constants.CATEGORY_FIRST_PROVINCE, new { @style = "width:120px" })%>
        </td>
        <td width="42%">
            <%=Html.DropDownList("MasterDistrictList", null, Constants.CATEGORY_FIRST_DISTRICT, new { @style = "width:150px" })%>
        </td>
        <td width="1%">
            <%= Html.DropDownList("GlobalCategory",null,"Chọn danh mục...", new { @style = "width: 170px;" })%>
        </td>
        <td width="42%">
            <input type="text" maxlength="100" style="width: 150px; height: 12px" value="<%=Constants.GLOBAL_FILTER_TEXT_DEFAULT %>"
                id="txtGlobalSearch" name="txtGlobalSearch" onfocus="JS_LIB.ShowOnFocus(this,'<%=Constants.GLOBAL_FILTER_TEXT_DEFAULT %>')"
                onblur="JS_LIB.ShowOnBlur(this,'<%=Constants.GLOBAL_FILTER_TEXT_DEFAULT %>')" />
        </td>
        <td width="1%">
            &nbsp;
        </td>
        <td width="11%">
            <a id="btnSearch" href="javascript:void(0)">
                <img src="../../Themes/images/home_24.jpg" width="83" height="24" alt="" /></a>
        </td>
        <td width="2%">
            &nbsp;
        </td>
    </tr>
</table>
<script type="text/javascript">

    $(document).ready(function () {
        JS_LIB.onEnterKeyword();
        $("#MasterProvinceList").change(function () {
            var provinceID = $("#MasterProvinceList").val();
            $("#MasterDistrictList").html("");
            $("#MasterDistrictList").append($("<option value=''><%= Constants.CATEGORY_FIRST_DISTRICT %></option>"));
            if (provinceID != 0) {
                $.getJSON('/Library/GenericHandle/DropdownListHandler.ashx?ID=' + provinceID + '&Page=District', function (item) {
                    $.each(item, function () {
                        $("#MasterDistrictList").append($("<option value='" + this['ID'] + "'>" + this['Name'] + "</option>"));
                    });
                });
            }
        });

        $("#btnSearch").click(function () {
            $.ajax({
                type: "POST",
                cache: false,
                url: "/Home/SetFilter",
                data: {
                    txtGlobalSearch: $("#txtGlobalSearch").val(),
                    GlobalCategory: $("#GlobalCategory").val(),
                    MasterProvinceList: $("#MasterProvinceList").val(),
                    MasterDistrictList: $("#MasterDistrictList").val()
                },
                success: function (data) {
                    if (data.MsgType == 1) {
                        JS_LIB.alert(data.MsgText, 'Thông Báo', false);
                    }
                    else {
                        JS_LIB.redirect('/timkiem.html');
                    }
                }
            });
        });
    });
</script>
